// ignore_for_file: file_names, use_key_in_widget_constructors, prefer_typing_uninitialized_variables, library_private_types_in_public_api
import 'package:aitao_flutter/model/gift_list_model.dart';
import 'package:aitao_flutter/pop_window/show_center_tips.dart';
import 'package:aitao_flutter/utils/sp_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_pickers/time_picker/model/pduration.dart';
import '../model/personal_model.dart';
import '../pop_window/show_center_input.dart';
import '../pop_window/show_gift_sheet.dart';
import '../pop_window/show_greet_sheet.dart';
import '../pop_window/show_guard_alert.dart';
import '../pop_window/show_share_sheet.dart';
import '../pop_window/show_image_sheet.dart';
import '../pop_window/show_list_sheet.dart';

class AlertUtils {
  /// 弹出消息不再提示框
  ///
  showImNotTipsDialog(
      BuildContext context, String tipStr, Function(String) actionCallBack) {
    if (SpUtil.getUserData().userinfo?.gender == 1) {
      tipStr = '$tipStr 通过主播认证私信免费';
    }
    showDialog(
        context: context,
        builder: (bContext) {
          return CupertinoAlertDialog(
              title: Text(tipStr),
              actions: setIMNotTipsAction(bContext, actionCallBack));
        });
  }

  List<Widget> setIMNotTipsAction(
      BuildContext actionContext, Function(String) actionCallBack) {
    CupertinoDialogAction okAction = CupertinoDialogAction(
      child: const Text('不再提醒'),
      onPressed: () {
        Navigator.pop(actionContext);
        SpUtil.savePayIMNotTip(true);
        actionCallBack('不再提醒');
      },
    );
    CupertinoDialogAction cancelAction = CupertinoDialogAction(
      child: const Text('知道了'),
      onPressed: () {
        Navigator.pop(actionContext);
        actionCallBack('知道了');
      },
    );
    CupertinoDialogAction verifyAction = CupertinoDialogAction(
      child: const Text('立即认证'),
      onPressed: () {
        Navigator.pop(actionContext);
        actionCallBack('立即认证');
      },
    );
    CupertinoDialogAction vipAction = CupertinoDialogAction(
      child: const Text('成为会员'),
      onPressed: () {
        Navigator.pop(actionContext);
        actionCallBack('成为会员');
      },
    );
    List<Widget> actions = [];
    if (SpUtil.getUserData().userinfo?.gender == 1) {
      actions.add(okAction);
      actions.add(cancelAction);
      actions.add(verifyAction);
    } else {
      actions.add(cancelAction);
      actions.add(okAction);
      if (SpUtil.getUserData().userinfo?.vip == 2) {
        actions.add(vipAction);
      }
    }
    return actions;
  }

  /// 底部弹出礼物
  showGiftSheet(BuildContext context, VoidCallback rechargeCallBack,
      Function(GiftItem) sendGiftCallBack) {
    showCupertinoModalPopup(
        context: context,
        builder: (bContext) {
          return ShowGiftSheetWidget(
              rechargeCallBack: rechargeCallBack,
              sendGiftCallBack: sendGiftCallBack);
        });
  }

  /// 中间守护弹窗
  showGuardDialog(
      BuildContext context, PersonalGuard guard, Function(int) guardCallBack) {
    showDialog(
        // barrierDismissible: false,
        context: context,
        builder: (builder) {
          return ShowGuardAlert(
            guard: guard,
            guardCallBack: guardCallBack,
          );
        });
  }

  /// 底部弹出打招呼弹窗
  ///
  showGreetSheet(
      BuildContext context,
      VoidCallback addCallback,
      Function(String) greetTextCallback,
      Function(int) greetImageCallback,
      Function(int) greetVoiceCallback) {
    showCupertinoModalPopup(
        context: context,
        builder: (bContext) {
          return ShowGreetSheetWidget(
              addCallback: addCallback,
              greetTextCallback: greetTextCallback,
              greetImageCallback: greetImageCallback,
              greetVoiceCallback: greetVoiceCallback);
        });
  }

  /// 中间弹出提示框
  showCenterTipsDialog(
      BuildContext context, confirmCallback, String title, String des,
      {String option1 = '确认', String option2 = '取消'}) {
    showCupertinoDialog(
      context: context,
      builder: (context) {
        return ShowCenterTipsWidget(
          title: title,
          des: des,
          option1: option1,
          option2: option2,
          confirmCallback: confirmCallback,
        );
      },
    );
  }

  /// 弹出图片选择框
  showImageSheet(BuildContext context, confirmCallback,
      {bool canPhoto = true}) {
    showCupertinoModalPopup(
        context: context,
        builder: (context) {
          return ShowImageSheetWidget(
              confirmCallback: confirmCallback, canPhoto: canPhoto);
        });
  }

  /// 弹出分享框
  showShareSheet(BuildContext context, confirmCallback,
      {bool canPhoto = true}) {
    showCupertinoModalPopup(
        context: context,
        builder: (context) {
          return ShowShareSheet(
            itemCallBack: confirmCallback,
          );
        });
  }

  /// 底部弹出N个选项框
  showBottomListAlert(BuildContext context, confirmCallback, String title,
      List<String> options) {
    showCupertinoModalPopup(
        context: context,
        builder: (context) {
          return ShowListActionWidget(
            options: options,
            title: title,
            confirmCallback: confirmCallback,
          );
        });
  }

  /// 中间弹出输入框
  showCenterInputAlert(
      BuildContext context, confirmCallback, String title, String placeholder,
      {TextInputType type = TextInputType.text}) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return ShowInputAlertWidget(
              confirmCallback, title, placeholder, type);
        });
  }

  /// 底部弹出日期1
  showBottomDateSheet(BuildContext context, confirmCallBack,
      {String currentBirthday = ''}) {
    DateTime dateTime;
    if (currentBirthday.isNotEmpty) {
      dateTime = DateTime.parse(currentBirthday);
    } else {
      dateTime = DateTime.now();
    }
    Pickers.showDatePicker(context,
        selectDate: PDuration(
            year: dateTime.year, month: dateTime.month, day: dateTime.day),
        minDate: PDuration(year: 1950),
        maxDate: PDuration(
            year: DateTime.now().year - 18,
            month: DateTime.now().month,
            day: DateTime.now().day), onConfirm: (res) {
      String birthday =
          '${res.year}-${res.month.toString().padLeft(2, '0')}-${res.day.toString().padLeft(2, '0')}';
      confirmCallBack(birthday);
    });
  }
}

// 430
